<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <!-- 引入react核心库 -->
  <script src="../js/react.development.js"></script>
  <!-- 引入react-dom,用于支持react操作DOM -->
  <script src="../js/react-dom.development.js"></script>
  <!-- 引入babel,用于将jsx转换为js -->
  <script src="../js/babel.min.js"></script>
  <!-- 引入prop-types,用于对组件标签属性进行限制 -->
  <script src="../js/prop-types.js"></script>

  <body>
    <!-- 容器 -->
    <div id="app"></div>
  </body>

  <script type="text/babel">
    function Person(props) {
      console.log(props);

      const { name, age, gender } = props;

      return (
        <ul>
          <li>姓名：{name}</li>
          <li>年龄：{age}</li>
          <li>性别：{gender}</li>
        </ul>
      );
    }

    //对标签属性进行类型和必要性的限制
    Person.propTypes = {
      name: PropTypes.string.isRequired, //限制name的类型是字符串且必传
      gender: PropTypes.string, //限制gender的类型是字符串
      age: PropTypes.number, //限制age的类型是数值
    };

    //指定默认标签属性值
    Person.defaultProps = {
      gender: "女", //默认gender的值是女
      age: 18, //默认age的值是18
    };

    ReactDOM.render(
      <Person name="周露" age={18} gender="女" />,
      document.getElementById("app")
    );
  </script>
</html>
